/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Practica4.Practica;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;

/**
 *
 * @author miguel
 */
public class Ordenamientos extends javax.swing.JFrame {

    /**
     * Creates new form Ordenamientos
     */
    public Ordenamientos() {
        initComponents();
        this.setTitle("Ordenamientos");
        ab = new AlgoritmosOrdenamientos();
        ae = new MyIntegerArray();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboOrdenamientos = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jComboArreglos = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextResultados = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jButtonGenerarGNUPlot = new javax.swing.JButton();
        jTextFieldTamano = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldlow = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldHigh = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jComboOrdenamientos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "HeapSort", "InsertionSort", "LocalInsertionSort", "MergeSort", "QuickSortAverage", "QuickSortMiddle", "QuickSortRandom", "ShellSort" }));
        jComboOrdenamientos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboOrdenamientosActionPerformed(evt);
            }
        });

        jLabel1.setText("Selecciona Algoritmo");

        jLabel2.setText("Generar arreglo");

        jComboArreglos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arreglo random", "Arreglo zigzag", "Arreglo inverso" }));
        jComboArreglos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboArreglosActionPerformed(evt);
            }
        });

        jButton1.setText("Ejecutar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Tamaño");

        jTextResultados.setColumns(20);
        jTextResultados.setEditable(false);
        jTextResultados.setRows(5);
        jScrollPane1.setViewportView(jTextResultados);

        jLabel4.setText("Generar gráfica gnuplot");

        jButtonGenerarGNUPlot.setText("Generar gnuplot");
        jButtonGenerarGNUPlot.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGenerarGNUPlotActionPerformed(evt);
            }
        });

        jLabel5.setText("low");

        jLabel6.setText("high");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonGenerarGNUPlot))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jComboOrdenamientos, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jComboArreglos, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldTamano, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                                    .addComponent(jTextFieldHigh))
                                .addGap(33, 33, 33)
                                .addComponent(jLabel5)
                                .addGap(56, 56, 56)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextFieldlow))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboOrdenamientos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboArreglos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldTamano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldlow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldHigh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jButtonGenerarGNUPlot))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonGenerarGNUPlotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGenerarGNUPlotActionPerformed
        try {
            // TODO add your handling code here:
            File f = new File("datosEjecucion.txt");
            try (PrintWriter pw = new PrintWriter(new FileWriter(f))) {
                int[] tam = {10, 100, 200, 500, 1000, 2000, 5000, 10000};
                int size = tam.length;
                String s = "";
                MyWorstCases mwc = new MyWorstCases();


                for (int i = 0; i < tam.length; i++) {
                    s += i + "\t";
                    long time = System.currentTimeMillis();
                    ab.heapSort(mwc.reverseSequence(tam[i]));
                    time = System.currentTimeMillis() - time;
                    s += time + "\t";
                    time = System.currentTimeMillis();
                    ab.insertionSort(mwc.reverseSequence(tam[i]));
                    time = System.currentTimeMillis() - time;
                    s += time + "\t";
                    time = System.currentTimeMillis();
                    ab.localInsertionSort(mwc.forLocalInsertionSort(tam[i]));
                    time = System.currentTimeMillis() - time;
                    s += time + "\t";
                    time = System.currentTimeMillis();
                    ab.mergeSort(ae.random(tam[i], 0, tam[i]));
                    time = System.currentTimeMillis() - time;
                    s += time + "\t";
                    time = System.currentTimeMillis();
                    ab.quickSortAverage(ae.random(tam[i], 0, tam[i]));
                    time = System.currentTimeMillis() - time;
                    s += time + "\t";
                    time = System.currentTimeMillis();
                    ab.quickSortMiddle(mwc.forQuickSort(tam[i]));
                    time = System.currentTimeMillis() - time;
                    s += time + "\t";
                    time = System.currentTimeMillis();
                    ab.quickSortRandom(mwc.forQuickSort(tam[i]));
                    time = System.currentTimeMillis() - time;
                    s += time + "\t";
                    time = System.currentTimeMillis();
                    int[] array = ae.zigZag(tam[i], tam.length / 2);
                    ae.inverse(array);
                    ab.shellSort(array);
                    time = System.currentTimeMillis() - time;
                    s += time + "\t";
                    pw.println(s);
                    s = "";
                    System.out.println("Ejecutando iteración: " + i);
                }
            }
            System.out.println("terminado de generar");
            String line;

            ProcessBuilder builder = new ProcessBuilder("/bin/bash");
            Process process;
            builder.redirectErrorStream(true);
            process = builder.start();

            OutputStream stdin = process.getOutputStream();
            InputStream stdout = process.getInputStream();

            BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));


            String input = "gnuplot plot1.txt";//, using 1:3 with lines, using 1:4 with lines, using 1:5 with lines, using 1:6 with lines, using 1:7 with lines, using 1:8 with lines, using 1:9 with lines";
            System.out.println("~$: " + input);


            writer.write("((" + input + ") && echo --EOF--) || echo --EOF--\n");

            writer.flush();


            line = reader.readLine();
            while (line != null && !line.trim().equals("--EOF--")) {

                System.out.println(": " + line);
                line = reader.readLine();
            }

            reader.close();
            writer.close();
            process.destroy();
        } catch (IOException ex) {
            Logger.getLogger(Ordenamientos.class.getName()).log(Level.SEVERE, null, ex);
            System.err.println(ex.getMessage());
            System.err.println("Error en la ejecución del comando");
        }

    }//GEN-LAST:event_jButtonGenerarGNUPlotActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if (this.jComboOrdenamientos.getSelectedItem().equals("HeapSort")) {
            if (this.jComboArreglos.getSelectedItem().equals("Arreglo random")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int low = Integer.parseInt(jTextFieldlow.getText());
                int high = Integer.parseInt(jTextFieldHigh.getText());

                int[] array = ae.random(n, low, high);
                String data = "HeapSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.heapSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextFieldlow.setText("");
                jTextFieldHigh.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo zigzag")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int[] array = ae.zigZag(n, n / 2);
                String data = "HeapSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.heapSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo inverso")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                MyWorstCases mwc = new MyWorstCases();
                int[] array = mwc.reverseSequence(n);
                String data = "HeapSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.heapSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            }
        } else if (jComboOrdenamientos.getSelectedItem().equals("InsertionSort")) {
            if (this.jComboArreglos.getSelectedItem().equals("Arreglo random")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int low = Integer.parseInt(jTextFieldlow.getText());
                int high = Integer.parseInt(jTextFieldHigh.getText());

                int[] array = ae.random(n, low, high);
                String data = "InsertionSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.insertionSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextFieldlow.setText("");
                jTextFieldHigh.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo zigzag")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int[] array = ae.zigZag(n, n / 2);
                String data = "InsertionSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.insertionSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo inverso")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                MyWorstCases mwc = new MyWorstCases();
                int[] array = mwc.reverseSequence(n);
                String data = "InsertionSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.insertionSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            }
        } else if (jComboOrdenamientos.getSelectedItem().equals("LocalInsertionSort")) {
            if (this.jComboArreglos.getSelectedItem().equals("Arreglo random")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int low = Integer.parseInt(jTextFieldlow.getText());
                int high = Integer.parseInt(jTextFieldHigh.getText());

                int[] array = ae.random(n, low, high);
                String data = "LocalInsertionSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.localInsertionSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextFieldlow.setText("");
                jTextFieldHigh.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo zigzag")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int[] array = ae.zigZag(n, n / 2);
                String data = "LocalInsertionSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.localInsertionSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo inverso")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                MyWorstCases mwc = new MyWorstCases();
                int[] array = mwc.reverseSequence(n);
                String data = "LocalInsertionSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.localInsertionSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            }
        } else if (jComboOrdenamientos.getSelectedItem().equals("MergeSort")) {
            if (this.jComboArreglos.getSelectedItem().equals("Arreglo random")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int low = Integer.parseInt(jTextFieldlow.getText());
                int high = Integer.parseInt(jTextFieldHigh.getText());

                int[] array = ae.random(n, low, high);
                String data = "MergeSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.mergeSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextFieldlow.setText("");
                jTextFieldHigh.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo zigzag")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int[] array = ae.zigZag(n, n / 2);
                String data = "MergeSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.mergeSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo inverso")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                MyWorstCases mwc = new MyWorstCases();
                int[] array = mwc.reverseSequence(n);
                String data = "MergeSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.mergeSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            }
        } else if (jComboOrdenamientos.getSelectedItem().equals("QuickSortAverage")) {
            if (this.jComboArreglos.getSelectedItem().equals("Arreglo random")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int low = Integer.parseInt(jTextFieldlow.getText());
                int high = Integer.parseInt(jTextFieldHigh.getText());

                int[] array = ae.random(n, low, high);
                String data = "QuickSort Average\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortAverage(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextFieldlow.setText("");
                jTextFieldHigh.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo zigzag")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int[] array = ae.zigZag(n, n / 2);
                String data = "QuickSort Average\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortAverage(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo inverso")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                MyWorstCases mwc = new MyWorstCases();
                int[] array = mwc.reverseSequence(n);
                String data = "QuickSort Average\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortAverage(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            }
        } else if (jComboOrdenamientos.getSelectedItem().equals("QuickSortMiddle")) {
            if (this.jComboArreglos.getSelectedItem().equals("Arreglo random")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int low = Integer.parseInt(jTextFieldlow.getText());
                int high = Integer.parseInt(jTextFieldHigh.getText());

                int[] array = ae.random(n, low, high);
                String data = "QuickSort Middle\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortMiddle(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextFieldlow.setText("");
                jTextFieldHigh.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo zigzag")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int[] array = ae.zigZag(n, n / 2);
                String data = "QuickSort Middle\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortMiddle(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo inverso")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                MyWorstCases mwc = new MyWorstCases();
                int[] array = mwc.reverseSequence(n);
                String data = "QuickSort Middle\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortMiddle(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            }
        } else if (jComboOrdenamientos.getSelectedItem().equals("QuickSortRandom")) {
            if (this.jComboArreglos.getSelectedItem().equals("Arreglo random")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int low = Integer.parseInt(jTextFieldlow.getText());
                int high = Integer.parseInt(jTextFieldHigh.getText());

                int[] array = ae.random(n, low, high);
                String data = "QuickSort Random\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortRandom(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextFieldlow.setText("");
                jTextFieldHigh.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo zigzag")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int[] array = ae.zigZag(n, n / 2);
                String data = "QuickSort Random\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortRandom(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo inverso")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                MyWorstCases mwc = new MyWorstCases();
                int[] array = mwc.reverseSequence(n);
                String data = "QuickSort Random\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.quickSortRandom(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            }
        } else if (jComboOrdenamientos.getSelectedItem().equals("ShellSort")) {
            if (this.jComboArreglos.getSelectedItem().equals("Arreglo random")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int low = Integer.parseInt(jTextFieldlow.getText());
                int high = Integer.parseInt(jTextFieldHigh.getText());

                int[] array = ae.random(n, low, high);
                String data = "ShellSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.shellSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextFieldlow.setText("");
                jTextFieldHigh.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo zigzag")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                int[] array = ae.zigZag(n, n / 2);
                String data = "ShellSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.shellSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            } else if (this.jComboArreglos.getSelectedItem().equals("Arreglo inverso")) {
                long time = System.currentTimeMillis();
                int n = Integer.parseInt(this.jTextFieldTamano.getText());
                MyWorstCases mwc = new MyWorstCases();
                int[] array = mwc.reverseSequence(n);
                String data = "ShellSort\nArreglo sin ordenar: a = [";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                data += "]\n";
                array = ab.shellSort(array);
                data += "Arreglo ordenado: a=[";
                for (int i = 0; i < array.length; i++) {
                    data += " " + array[i] + " ";
                }
                time = System.currentTimeMillis() - time;
                data += "]\nTiempo de ejecución: " + time;
                jTextFieldTamano.setText("");
                jTextResultados.setText("");
                jTextResultados.setText(data);
            }
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jComboOrdenamientosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboOrdenamientosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboOrdenamientosActionPerformed

    private void jComboArreglosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboArreglosActionPerformed
        // TODO add your handling code here:
        if (jComboArreglos.getSelectedItem().equals("Arreglo random")) {
            jTextFieldHigh.setEditable(true);
            jTextFieldlow.setEditable(true);
        } else {
            jTextFieldHigh.setEditable(false);
            jTextFieldlow.setEditable(false);

        }
    }//GEN-LAST:event_jComboArreglosActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Ordenamientos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Ordenamientos().setVisible(true);
            }
        });
    }
    //
    AlgoritmosOrdenamientos ab;
    MyIntegerArray ae;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonGenerarGNUPlot;
    private javax.swing.JComboBox jComboArreglos;
    private javax.swing.JComboBox jComboOrdenamientos;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextFieldHigh;
    private javax.swing.JTextField jTextFieldTamano;
    private javax.swing.JTextField jTextFieldlow;
    private javax.swing.JTextArea jTextResultados;
    // End of variables declaration//GEN-END:variables
}
